﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ReconUI
{
    public partial class SelectDate : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Populate_MonthList();
                Populate_YearList();
            }
            control.Value = Request.QueryString["textbox"].ToString();
        }

        public void Populate_MonthList()
        {
            cmbMonth.Items.Add("January");
            cmbMonth.Items.Add("February");
            cmbMonth.Items.Add("March");
            cmbMonth.Items.Add("April");
            cmbMonth.Items.Add("May");
            cmbMonth.Items.Add("June");
            cmbMonth.Items.Add("July");
            cmbMonth.Items.Add("August");
            cmbMonth.Items.Add("September");
            cmbMonth.Items.Add("October");
            cmbMonth.Items.Add("November");
            cmbMonth.Items.Add("December");
            cmbMonth.Items.FindByText(DateTime.Now.ToString("MMMM")).Selected = true;
        }

        public void Populate_YearList()
        {
            //Year list can be extended
            int intYear;
            for (intYear = DateTime.Now.Year - 20; intYear <= DateTime.Now.Year + 20; intYear++)
            {
                cmbYear.Items.Add(intYear.ToString());

            }
            cmbYear.Items.FindByText(DateTime.Today.Year.ToString()).Selected = true;


        }

        public void Set_Calendar(object sender, EventArgs e)
        {
            //Whenever month or year selection changes display the calendar for that month/year        
            calDate.TodaysDate = DateTime.Parse(cmbMonth.SelectedItem.Value + "1," + cmbYear.SelectedItem.Value);

        }

        protected void calDate_SelectionChanged(object sender, EventArgs e)
        {
            //   document.getElementById('<%=myTextbox.ClientID%>');
            String strScript = "<script>window.opener.document.all('" + control.Value + "').value = '";

            strScript += calDate.SelectedDate.ToString("dd-MM-yyyy");
            strScript += "';self.close();";
            strScript += "</script>";

            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "anything", strScript);
        }

        protected void cmbYear_SelectedIndexChanged(object sender, EventArgs e)
        {
            Set_Calendar(sender, e);
        }

        protected void cmbMonth_SelectedIndexChanged(object sender, EventArgs e)
        {
            Set_Calendar(sender, e);
        }





    }
}